import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import "rxjs/add/operator/map";
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import {URLSearchParams} from "@angular/http";
import {HttpURLService} from "../../../httpURL.service";
@Injectable()
export class PointService {
  public emisurl:string = this.httpURLService.getUrl("emis");
  private equimentUrl = this.emisurl+'/equipment/queryEquipmentList?firstType=005';//设备名称
  private areaUrl = this.emisurl+'/baseAdminArea/queryAreaList';//行政区接口
  private listUrl = this.emisurl+'/basePolluter/queryDetailInfo';//获取列表
  private DataAcqListUrl =this.emisurl+ '/dataAcq/queryDataAcqList?id=';//数采仪列表这
  private queryEquipmentListUrl =this.emisurl+ '/equipment/queryEquipmentList?firstType=003,004';//设备名称
  private queryAcqEquipmentListUrl = this.emisurl+'/acqEquipment/queryAcqEquipmentList?id=';//污染物设备名称
  private deleteUrl = this.emisurl+'/port/deletePort';//删除排放口接口
  private addUrl = this.emisurl+'/port/addPort';//添加排放口接口
  private editUrl = this.emisurl+'/port/updatePort';//编辑排放口接口
  private monitorUrl = this.emisurl+'/baseMonitor/queryMonitorList';//关联监控点接口
  private portUrl = this.emisurl+'/port/queryPortList';//关联排放口接口
  private addmonitorUrl = this.emisurl+'/baseMonitor/addMonitor';//添加监控点接口
  private editmonitorUrl = this.emisurl+'/baseMonitor/updateMonitor';//编辑监控点接口
  private deletemonitorUrl = this.emisurl+'/baseMonitor/deleteMonitor';//删除监控点接口
  private addequimentUrl = this.emisurl+'/acqEquipment/addAcqEquipment';//添加数采仪设备
  private editequimentUrl = this.emisurl+'/acqEquipment/updateAcqEquipment';//编辑数采仪设备
  private deleteequimentUrl = this.emisurl+'/acqEquipment/deleteAcqEquipment';//删除数采仪设备
  private acqUrl =this.emisurl+ '/dataAcq/queryDetailById';//数采仪关联信息查看详情
  private addacqUrl =this.emisurl+ '/dataAcq/addDataAcq';//添加数采仪关联信息
  private editacqUrl =this.emisurl+ '/dataAcq/updateDataAcq';//编辑数采仪关联信息
  private deletetacqUrl = this.emisurl+'/dataAcq/deleteDetailById';//删除数采仪关联信
  //设备污染物信息
  private addEquiPollutantUrl =this.emisurl+ '/equiPollutant/addEquiPollutantBatch';
  private queryEquiPollutantByIdUrl =this.emisurl+ '/equiPollutant/queryEquiPollutantById';/**根据id查询一个关联设备因子详细信息接口*/
  private updateEquiPollutantBatchUrl = this.emisurl+'/equiPollutant/updateEquiPollutantBatch';/**批量更新点位设备因子关联关系*/
  private deleteEquiPollutantUrl =this.emisurl+ '/equiPollutant/deleteEquiPollutant';/**根据id删除一个关联设备因子接口*/
  private codeListUrl =this.emisurl+ '/detectableCode/queryDetectableCodeList?equipId=';//检测因子接口
  constructor(private http: HttpClient,
              private httpURLService: HttpURLService) { }
  getCodeList(id): Observable<any> {
    return this.http.get(`${this.codeListUrl}${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //查看污染物信息详情
  deleteEquiPollutant(id): Observable<any> {
    return this.http.get(`${this.deleteEquiPollutantUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //查看污染物信息详情
  lookEquiPollutant(id): Observable<any> {
    return this.http.get(`${this.queryEquiPollutantByIdUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
 getMonitor(id): Observable<any> {
    return this.http.get(`${this.monitorUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //关联数采仪
  getDataAcqList(id): Observable<any> {
    return this.http.get(`${this.DataAcqListUrl}${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  getqueryEquipmentList(){
    return this.http.get(`${this.queryEquipmentListUrl}`)
      .map(data =>data)
      .catch(this.handleError);
}
  queryAcqEquipmentList(id){
    return this.http.get(`${this.queryAcqEquipmentListUrl}${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //关联排放口
  getPort(id): Observable<any> {
    return this.http.get(`${this.portUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //设备名称
  getEquipment(): Observable<any> {
    return this.http.get(`${this.equimentUrl}`)
      .map(data => data)
      .catch(this.handleError);
  }
  //行政区
  getArea(): Observable<any> {
    return this.http.get(`${this.areaUrl}`)
      .map(data => data)
      .catch(this.handleError);
  }
  //查看数采仪详情
  getAcqList(id){
    return this.http.get(`${this.acqUrl}/${id}`)
      .map(data => data)
      .catch(this.handleError);
  }
  getLists(id): Observable<any> {
    return this.http.get(`${this.listUrl}/${id}`)
      .map(data => data)
      .catch(this.handleError);
  }
//查询列表
  getExhibits(queryData): Observable<any> {
    return this.http.get(`${this.listUrl}?${queryData}`)
      .map(data => data)
      .catch(this.handleError);
  }
  //删除
  deletePoint(id): Observable<any> {
    return this.http.get(`${this.deleteEquiPollutantUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //添加
  createPoint(data): Observable<any> {
    return this.http.post(`${this.addEquiPollutantUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  editPoint(data): Observable<any> {
    return this.http.post(`${this.updateEquiPollutantBatchUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  //删除
  deleteMonitor(id): Observable<any> {
    return this.http.get(`${this.deletemonitorUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //添加
  createMonitor(data): Observable<any> {
    return this.http.post(`${this.addmonitorUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  editMonitor(data): Observable<any> {
    return this.http.post(`${this.editmonitorUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  //删除
  deleteEqui(id): Observable<any> {
    return this.http.get(`${this.deletetacqUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //添加
  createEqui(data): Observable<any> {
    return this.http.post(`${this.addacqUrl}`, data,{headers: new HttpHeaders({'Content-Type': 'application/json; charset=UTF-8' })})
      .map(data =>data)
      .catch(this.handleError);
  }
  editEqui(data): Observable<any> {
    return this.http.post(`${this.editacqUrl}`, data,{headers: new HttpHeaders({'Content-Type': 'application/json; charset=UTF-8' })})
      .map(data =>data)
      .catch(this.handleError);
  }
  //删除1数采仪设备
  deleteEquiment(id): Observable<any> {
    return this.http.get(`${this.deleteequimentUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //添加
  createEquiment(data): Observable<any> {
    return this.http.post(`${this.addequimentUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  editEquiment(data): Observable<any> {
    return this.http.post(`${this.editequimentUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  //删除
  deletePollut(id): Observable<any> {
    return this.http.get(`${this.deleteUrl}/${id}`)
      .map(data =>data)
      .catch(this.handleError);
  }
  //添加
  createPollut(data): Observable<any> {
    return this.http.post(`${this.addUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  editExhibit(data): Observable<any> {
    return this.http.post(`${this.editUrl}`, data)
      .map(data =>data)
      .catch(this.handleError);
  }
  private handleError(error: Response | any) {
    let errMsg: string;
    if (error instanceof Response) {
      const body = error.json() || '';
      const err = body.error || JSON.stringify(body);
      errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    return Observable.throw(errMsg);
  }
}
